#ifndef CLIENT_H
#define CLIENT_H

#include <QWidget>
#include "stdshared.h"
#include "myclientsocket.h"
#include <QStackedWidget>
#include <QPixmap>
#include <QFile>
#include "voiceclient.h"

namespace Ui {
class Client;
}

class Client : public QWidget
{
    Q_OBJECT

public:
    explicit Client(const QString & account,QPixmap & pix,MyClientSocket * socket,QWidget *parent = nullptr);
    ~Client();
    void mousePressEvent(QMouseEvent *event) override;

    void mouseMoveEvent(QMouseEvent *event) override;

    void mouseReleaseEvent(QMouseEvent *event) override;

    void setContansAccount(QVector<QString>& accounts,QVector<QString>& notes,QVector<QPixmap> & pixs);

    void setSearchAccount(QVector<QString>& accounts,QVector<QString>& notes,QVector<QString>& flags,QVector<QPixmap> & pixs);

    // 将接受的信息塞入靠左的气泡框中 文字消息
    void setRecvdialoglist(const QString &accounts, const QString &message,const QPixmap & pix,const QString & time);
    // 将发送的信息塞入靠右的气泡框中 文字消息
    void setSentdialoglist(const QString &accounts, const QString &message,const QPixmap & pix,const QString & time);

    //图片消息
    void setRecvPixlist(const QString &accounts, QPixmap &message,const QPixmap & pix,const QString & time);
    //
    void setSentPixlist(const QString &accounts, QPixmap &message,const QPixmap & pix,const QString & time);

    void SetHeadPhoto(QMouseEvent *event);

    //重写鼠标右键点击事件
    void contextMenuEvent(QContextMenuEvent *event) override;

    void setGroupMember(QVector<QString>& group_accounts, QVector<QString> &power,QVector<QPixmap> &pixs);

    //群文字消息
    void GroupTextMsg(QJsonObject& jsonObj);
    //群图片消息
    void GroupPixMsg(QJsonObject& jsonObj);
    //个人文字消息
    void PersonTextMsg(QJsonObject& jsonObj);
    //个人图片消息
    void PersonPixMsg(QJsonObject& jsonObj);

    // 在线群聊头像获取
    QPixmap getGroupOnePix(QString & account);


public slots:

    void handleRecvSlot(const QByteArray &data);

    void handleCtsListDoubleClickedSlot();
    void handleGroupListDoubleClickedSlot();
    void handleSearListDoubleClickedSlot();

    void handleGetFriends(QVector<QString>& accounts,QVector<QString>& notes,QVector<QString>& flags,QVector<QPixmap> & pixs);

    void handleAddSignal(const QString & account,const QString & note);

    void handleSearchBtn();

    void handleDoubleClickedSlot();

    void handleSendBtn();

    void handleCreateGroup();

    void exitClient();

    void handleSettingSlot();

    void handleAddSlot();

    void handleMinusSlot();

    void handleDeleteSlot();

    void handleSetManagerSlot();

    void handleCloseBtn();

    //发图片
    void handleSendPix();

    void handleSendFileSlot();

    //导入历史记录
    void handleHistory(const QByteArray & data);

    void handleCallPhone();
private:
    Ui::Client *ui;
    QString m_account;
    MyClientSocket * m_socket;
    QStackedWidget * m_stacked;
    int m_flag;
    bool m_dragging = false;
    QPoint m_dragPosition;
    QString r_account;
    //存储好友
    QVector<QString> m_vector;
    //
    QVector<QString> m_notes;

    QVector<QPixmap> m_pixs;

    QPixmap m_headPix;

    QString m_file_path;
    QFile m_file;

    bool call_flag;
    VoiceClient *vClient;


};

#endif // CLIENT_H
